package cn.core.tool.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collection;

/**
 * 分页数据
 */
@Data
@Accessors(chain = true)
public class Paging<T> implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 第几页
   */
  private Long page;

  /**
   * 多少条
   */
  private Long rows;

  /**
   * 数据量
   */
  private Long count;

  /**
   * 数据
   */
  private Collection<T> data;

  /**
   * 数据库
   */
  private String db;

  /**
   * mysql oracle 偏移量
   */
  private Long offset;

  /**
   * oracle 开始偏移量
   */
  private Long offsetStart;

  /**
   * oracle 结束偏移量
   */
  private Long offsetEnd;

  public Paging() {
    super();
    this.db = CoreTool.mysql;
//    this.db = CoreTool.oracle;
//    this.db = CoreTool.oracle11;
  }

  public Paging(Param<?> param) {
    this();
    this.rows = param.getRows();
    this.page = param.getPage();
    this.offset = (param.getPage() - 1) * param.getRows();
    this.offsetStart = (param.getPage() - 1) * param.getRows() + 1;
    this.offsetEnd = param.getPage() * param.getRows();
  }

  public Paging(String db) {
    this();
    this.db = db;
  }

  public Paging(Param<?> param, String db) {
    this(param);
    this.db = db;
  }

}
